#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>

#define MAX_ANIMAL 1000
typedef struct HEAP Heap;
typedef int Graph;
typedef struct ELEMENTTYPE ElementType;

struct HEAP {
	ElementType *elm;
	int size;
	int capacity;
};
struct ELEMENTTYPE{
	int vetex;
	int dis;
};

Heap *HeapInit(int);
_Bool HeapEmpty(Heap*);
_Bool HeapFull(Heap*);
void EnHeap(Heap*,ElementType);
ElementType DeHeap(Heap*);

Heap *HeapInit(int max){
	Heap *ret=malloc(sizeof(Heap));
	ret->size=0;
	ret->capacity=max;
	ret->elm=malloc(sizeof(ElementType)*(max+1));
	ret->elm[0].dis=INT_MIN;
	return ret;
}
_Bool HeapEmpty(Heap *h){
	if(h->size)
		return false;
	return true;
}
_Bool HeapFull(Heap *h){
	if(h->size == h->capacity)
		return true;
	return false;
}
void EnHeap(Heap *h,ElementType elm){
	int i=++h->size;
	for(;elm.dis<h->elm[i/2].dis;i=i/2){
		h->elm[i]=h->elm[i/2];
	}
	h->elm[i]=elm;
	return;
}

ElementType DeHeap(Heap *h){
	ElementType ret=h->elm[1];
	ElementType e=h->elm[h->size--];
	if(0==h->size)return ret;
	int i=1;
	while( h->size >= 2*i ){
		if( (2*i)!=h->size && h->elm[2*i].dis>h->elm[2*i+1].dis && e.dis>h->elm[2*i+1].dis ){
			h->elm[i]=h->elm[2*i+1];
			i=2*i+1;
		}else if( e.dis > h->elm[i*2].dis ){
			h->elm[i]=h->elm[2*i];
			i=2*i;
		}else{
			break;
		}
	}
	h->elm[i]=e;
	//h->eml[i]=h->elm[h->size];
	return ret;
}
int Dijkstra(int n,Graph(*)[n],int,int *);

int main(void){
	int n,m;
	scanf("%d %d",&n,&m);
	Graph graph[n+1][n+1];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			//if( i == j )
			//	graph[i][j]=0;
			//else
				graph[i][j]=INT_MAX;
		}
	}
	int v1,v2,w,ret[n+1];
	for(int i=0;i<m;i++){
		scanf("%d %d %d",&v1,&v2,&w);
		graph[v1][v2]=graph[v2][v1]=w;
	}
	
	int vetex,dis,min_v,min_d;
	min_d=INT_MAX;
	for(int i=1;i<=n;i++){
		dis=INT_MIN;
		Dijkstra(n+1,graph,i,ret);
		for(int j=1;j<=n;j++){
			if(INT_MAX==ret[j]){
				printf("0\n");
				return 0;
			}
			else if( ret[j] > dis ){
				dis=ret[j];
				vetex=i;
			}else{}
		}
//printf("%d: %d %d\n",i,vetex,dis);
		if( dis < min_d ){
			min_d=dis;
			min_v=vetex;
		}
	}
	printf("%d %d",min_v,min_d);
	return 0;
}
int Dijkstra(int n,Graph(*graph)[n],int vetex,int *ret){
	_Bool visited[n];
	ElementType elm[n];
	//int path[n];
	for(int i=1;i<n;i++){
		visited[i]=false;
		elm[i].vetex=i;
		elm[i].dis=INT_MAX;
		//path[i]=-1;
	}
	elm[vetex].dis=0;
	Heap *h=HeapInit(MAX_ANIMAL);
	EnHeap(h,elm[vetex]);
	//dis[vetex]=0;
	//visited[vetex]=true;
	ElementType e;
	while( !HeapEmpty(h) ){
		e=DeHeap(h);
		visited[e.vetex]=true;
		for(int i=1;i<n;i++){
			//if( graph[e.vetex][i] < elm[i].dis && !visited[i] ){
			if( graph[e.vetex][i]!=INT_MAX && !visited[i] && (e.dis+graph[e.vetex][i] < elm[i].dis) ){
				elm[i].dis=e.dis+graph[e.vetex][i];
				EnHeap(h,elm[i]);
				//path[i]=e.vetex;
			}
		}
	}
for(int i=1;i<n;i++){
//	printf("%d-",elm[i].dis);
	ret[i]=elm[i].dis;
}
//printf("\n");
	return 0;
}
